<template>
    <div class="pie">
        <div :id="'circularpie' + cageId" :style="styles"></div>
    </div>
</template>

<script>
import echarts from 'echarts';
export default {
  data () {
    return {
      cageId: parseInt(Math.random() * 100000)
    };
  },
  mounted () {
    this.drawLine();
  },
  props: {
    // 样式
    styles: Object,
    // 参数数据
    paramsData: Array,
    // 提示数据
    xData: Array,
    // 标题
    title: String
  },
  methods: {
    drawLine () {
      let that = this;
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('circularpie' + that.cageId));
      // 绘制图表
      myChart.setOption({
        title: {
          text: that.title,
          x: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              normal: {
                show: false,
                position: 'center'
              },
              emphasis: {
                show: true,
                textStyle: {
                  fontSize: '30',
                  fontWeight: 'bold'
                }
              }
            },
            data: that.paramsData
          }
        ]
      });
    }
  }
};
</script>


<style lang="stylus" scoped>

</style>
